from urllib import request
import urllib


def demo1():
    """第一种下载的方式"""
    request.urlretrieve("https://gss3.bdstatic.com/7Po3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D220/sign=cb413304ebf81a4c2232ebcbe72b6029/a2cc7cd98d1001e9fe73957fb80e7bec54e79777.jpg",
    "module/urllib/aaa.jpg")

def demo2():
    """最原始的方式下载"""
    url = 'https://gss3.bdstatic.com/7Po3dSag_xI4khGkpoWK1HF6hhy/baike/s%3D220/sign=cb413304ebf81a4c2232ebcbe72b6029/a2cc7cd98d1001e9fe73957fb80e7bec54e79777.jpg'
    urll = urllib.request.Request(url) # Request() 函数将url添加到头部，　模拟浏览器访问

    page = urllib.request.urlopen(urll).read() # 将url页面的源代码保存成字符串

    open("module/urllib/bbb.jpg", 'wb').write(page) # 写入 bbb.jpg文件中

if __name__ == "__main__":
    pass

    demo2()